package vmcs.customer.state;

import vmcs.common.VMCSException;
import vmcs.controller.TransactionController;
import vmcs.store.DrinksBrand;
import vmcs.store.DrinksStore;
import vmcs.store.Store;
import vmcs.store.StoreItem;

public class IdleState implements State{
	
	private TransactionController transactionController;
	
	private static IdleState instance;
	
	private IdleState(TransactionController transactionController) {
		this.transactionController = transactionController;
	}
	
	public static IdleState getInstance(TransactionController transactionController) {
		if (instance == null) 
			instance = new IdleState(transactionController);
		return instance;
	} 

	@Override
	public void selectDrink(int selectedIdx) {
		Store drinkStore = (DrinksStore)transactionController.getMainController().getStoreController().getStore(Store.DRINK);
		
		transactionController.setSelection(selectedIdx);
		try {
			StoreItem drinkSelectedStoreItem  = drinkStore.getStoreItem(selectedIdx);
			DrinksBrand selectedDrinkBrand = (DrinksBrand) drinkSelectedStoreItem.getContent();
			transactionController.setPrice(selectedDrinkBrand.getPrice());

			transactionController.getChangeGiver().resetChange();
			transactionController.getDispenseController().resetCan();
			transactionController.getChangeGiver().displayChangeStatus();
			transactionController.getDispenseController().allowSelection(false);
			transactionController.getCoinReceiver().startReceive();

		} catch (VMCSException e) {
			e.printStackTrace();
		}
		
		// Change state
		transactionController.setState(transactionController.getDrinkSelectedState());	
	}



	@Override
	public void cancel() {
		// DO NOTHING
	}

	@Override
	public void insertCoin(int value) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispenseDrink(int drinkSelected) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void giveChange(int changeRequired) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void storeCash() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void terminateMachine() {
		
	} 



}
